/***
 * Excerpted from "Programming Groovy",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/vslg for more book information.
***/
println "//" + "START:TOSSN_OUTPUT"

class StringUtil {
	//write toSSN(String self) to restrict to String
  	def static toSSN(self) {
		if (self.size() == 9) {
	  		return "${self[0..2]}-${self[3..4]}-${self[5..8]}"
		}
  	}
}

use(StringUtil) {
	println "123456789".toSSN()
	println new StringBuffer("987654321").toSSN()
}

try {
	println "123456789".toSSN()
} catch(MissingMethodException ex) {
  println ex.message
}

println "//" + "END:TOSSN_OUTPUT"